<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dict">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.complainantName"
            placeholder="投诉人姓名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.complainantPhone"
            placeholder="联系电话"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.islandId"
            placeholder="所属区域"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="item in scenicOptions"
              :key="item.id"
              :label="item.scenicName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-select
            v-model="dataForm.complainantType"
            placeholder="类型"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in types"
              :key="index"
              :label="item"
              :value="index"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.state"
            placeholder="状态"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in types2"
              :key="index"
              :label="item"
              :value="index"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="value1"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('scenic:workorder:delete')"
            type="danger"
            @click="deleteHandle(id)"
            >{{ $t("deleteBatch") }}</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('scenic:workorder:export')"
            type="primary"
            @click="exportHandle()"
            >导出</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
        :height="he"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <!-- <el-table-column prop="islandName" label="所在区域" min-width="120" align="center"></el-table-column>
            <el-table-column prop="complainantName" label="投诉人姓名" min-width="120" align="center"></el-table-column> -->
        <el-table-column
          prop="complainantId"
          label="投诉对象"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="phone"
          label="联系电话"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="reply"
          label="处理结果"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <!--<el-table-column-->
        <!--prop="pic"-->
        <!--label="图片"-->
        <!--header-align="center"-->
        <!--min-width="120"-->
        <!--align="center"-->
        <!--&gt;-->
        <!--<template slot-scope="scope">-->
        <!--<img :src="scope.row.pic" style="width:70px;height:70px" />-->
        <!--</template>-->
        <!--</el-table-column>-->
        <el-table-column
          prop="complainantType"
          label="投诉类型"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            {{ types[scope.row.complainantType] }}
          </template>
        </el-table-column>
        <el-table-column
          prop="state"
          label="状态 "
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            {{ types2[scope.row.state] }}
          </template>
        </el-table-column>
        <el-table-column
          prop="createDate"
          label="创建时间"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <!-- <el-button type="text" size="small" @click="end(scope.row.complainantId,scope.row.id)">结束工单</el-button> -->
            <el-button
              type="text"
              size="small"
              v-if="
                $hasPermission('scenic:workorder:update') &&
                scope.row.state == 0
              "
              @click="
                disabled = false;
                addOrUpdateHandle(scope.row.id);
              "
              >编辑</el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="
                $hasPermission('scenic:workorder:info') && scope.row.state == 1
              "
              @click="
                disabled = true;
                addOrUpdateHandle(scope.row.id);
              "
              >详情</el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="$hasPermission('scenic:workorder:info')"
              @click="deleteHandle(scope.row.id)"
              >{{ $t("delete") }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
        :disabled="disabled"
        @changeDisabled="disabled = false"
      ></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./workOrder-add-or-update";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      disabled: false,
      mixinViewModuleOptions: {
        getDataListURL: "/scenic/workOrder/page",
        getDataListIsPage: true,
        deleteURL: "/scenic/workOrder",
        deleteIsBatch: true,
        exportURL: "/scenic/workOrder/export",
      },
      he:'auto',
      scenicOptions: [],
      types: [
        "功能故障",
        "景区意见",
        "产品建议",
        "预订咨询",
        "订单咨询",
        "其他",
      ],
      types2: ["派单中", "已结束"],
      dataForm: {
        complainantName: "",
        complainantPhone: "",
        islandId: "",
        complainantType: "",
        state: "",
        startDate: "",
        endDate: "",
      },
      value1: [],
    };
  },
  components: {
    AddOrUpdate,
  },
  created() {
    this.getScenicOptions();
  },
  watch: {
     dataList(newval, oldval) {
      if (newval != oldval) {
        this.he = "auto";
        setTimeout(() => {
          this.he = "calc(100vh - 330px)";
        }, 500);
      }
    },
    value1(newval, oldval) {
      if (newval != oldval) {
        this.dataForm.startDate = newval[0];
        this.dataForm.endDate = newval[1];
      }
    },
  },
  methods: {
    getScenicOptions() {
      this.$http
        .get("scenic/isscenic/selectScenicList", {})
        .then(({ data: res }) => {
          if (res.msg == "success") {
            console.log(res);
            this.scenicOptions = res.data;
          }
        });
    },
    end(complaintld, id) {
      this.$confirm("确定该操作？", this.$t("prompt.title"), {
        confirmButtonText: this.$t("confirm"),
        cancelButtonText: this.$t("cancel"),
        type: "warning",
      })
        .then(() => {
          this.$http
            .get(`/scenic/workOrder/updateStateByld`, {
              params: {
                complaintld: complaintld,
                id: id,
              },
            })
            .then((res) => {
              if (res.data.code !== 0) {
                return this.$message.error(res.msg);
              }
              this.$message({
                message: this.$t("prompt.success"),
                type: "success",
                duration: 500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                },
              });
            });
        })
        .catch(() => {});
    },
    reply(id) {
      this.$prompt("请输入回复内容", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(({ value }) => {
          this.$http
            .put("/scenic/complaintrecommendation/reply", {
              id: id,
              reply: value,
            })
            .then((res) => {
              this.$message({
                type: "info",
                message: "取消输入",
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入",
          });
        });
    },
  },
};
</script>
